package com.xyz.admin.common.exception;

import com.sc.base.common.exception.RRException;
import com.xyz.admin.common.utils.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.IOException;
import java.sql.SQLSyntaxErrorException;

/**
 * 异常处理器
 * 
 *
 * @Auth liuwei
 * @date 2018年12月12日10:13:01
 */
@RestControllerAdvice
public class RRExceptionHandler {
	private Logger logger = LoggerFactory.getLogger(getClass());


	@ExceptionHandler(Exception.class)
	public R handleException(Exception e){
		logger.error(e.getMessage(), e);
		return R.error("服务器繁忙CODE:1");
	}

	@ExceptionHandler(IOException.class)
	public R handleDuplicateKeyException(DuplicateKeyException e){
		logger.error(e.getMessage(), e);
		return R.error("服务器繁忙CODE:2");
	}

	@ExceptionHandler(SQLSyntaxErrorException.class)
	public R handleSQLSyntaxErrorException(SQLSyntaxErrorException e){
		logger.error(e.getMessage(), e);
		return R.error("服务器繁忙CODE:3");
	}

	@ExceptionHandler(RRException.class)
	public R handleRRException(RRException e){
		logger.error(e.getMessage(), e);
		if(1111 == e.getCode()){
			return R.error(e.getMsg());
		}
		return R.error("服务器繁忙CODE:4");
	}




}
